using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Data;
using System.Data.SqlClient;

namespace MacViet.DataBaseAPI
{
    /// <summary>
    /// Description: Concrete DataProvider for table Payments. Provides atomic API functions.
    /// Author:  phong.huynh
    /// Created: 13/08/2010 9:43:19 SA
    /// </summary>
    public class PAYMENTSDataAPI
    {
        private SQLHelper _dbTool = new SQLHelper();


        // ************************************
        // Implements function getByColumnName
        // ************************************

        public DataTable getByPAY_ID(System.Int32 PAY_ID)
        {
            SqlParameter[] parm = { new SqlParameter(PAYMENTSDTO._PAY_ID, PAY_ID) };
            return _dbTool.executeReader("SP_SEL_PAYMENTS_getByPAY_ID", parm);
        }
        public DataTable getByPTYP_ID(System.Int32 PTYP_ID)
        {
            SqlParameter[] parm = { new SqlParameter(PAYMENTSDTO._PTYP_ID, PTYP_ID) };
            return _dbTool.executeReader("SP_SEL_PAYMENTS_getByPTYP_ID", parm);
        }

        public DataTable getByPAY_AMOUNT(System.Decimal PAY_AMOUNT)
        {
            SqlParameter[] parm = { new SqlParameter(PAYMENTSDTO._PAY_AMOUNT, PAY_AMOUNT) };
            return _dbTool.executeReader("SP_SEL_PAYMENTS_getByPAY_AMOUNT", parm);
        }

        public DataTable getByPAY_TIP(System.Decimal PAY_TIP)
        {
            SqlParameter[] parm = { new SqlParameter(PAYMENTSDTO._PAY_ID, PAY_TIP) };
            return _dbTool.executeReader("SP_SEL_PAYMENTS_getByPAY_TIP", PAY_TIP);
        }



        // *************************************************
        // Implement function getAll/getByDynamicCondition
        // *************************************************

        public DataTable getAll()
        {
            return _dbTool.executeReader("SP_SEL_PAYMENTS_getAll");
        }


        // ********************************************************
        // Implement function getByPrimaryKeys / getByForeignKeys
        // In case table have composite primary/foreign keys
        // ********************************************************

        public DataTable getByPrimaryKeys(System.Int32 PAY_ID)
        {
            SqlParameter[] parm = { new SqlParameter(PAYMENTSDTO._PAY_ID, PAY_ID) };
            return _dbTool.executeReader("SP_SEL_PAYMENTS_getByPrimaryKeys", parm);
        }

        public bool insertPAYMENTS(System.Int32 PTYP_ID, System.Decimal PAY_AMOUNT, System.Decimal PAY_TIP)
        {
            SqlParameter[] parm = { new SqlParameter(PAYMENTSDTO._PAY_ID,1),
                                    new SqlParameter(PAYMENTSDTO._PTYP_ID,PTYP_ID),
                                    new SqlParameter(PAYMENTSDTO._PAY_AMOUNT,PAY_AMOUNT),
                                    new SqlParameter(PAYMENTSDTO._PAY_TIP,PAY_TIP)};
            int effectedRows = _dbTool.ExecuteNoneQuery("SP_INS_PAYMENTS_values", parm);
            return (effectedRows == 1);
        }


        ///<summary>		
        /// Thu+.c hie^.n ca^u le^.nh update du+.a tre^n kho'a chi'nh
        ///</summary>

        public bool updatePAYMENTS(System.Int32 PAY_ID, System.Int32 PTYP_ID, System.Decimal PAY_AMOUNT, System.Decimal PAY_TIP)
        {
            SqlParameter[] parm = { new SqlParameter(PAYMENTSDTO._PAY_ID,PAY_ID),
                                    new SqlParameter(PAYMENTSDTO._PTYP_ID,PTYP_ID),
                                    new SqlParameter(PAYMENTSDTO._PAY_AMOUNT,PAY_AMOUNT),
                                    new SqlParameter(PAYMENTSDTO._PAY_TIP,PAY_TIP)};
            int affectRows = _dbTool.ExecuteNoneQuery("SP_UDP_PAYMENTS_update", parm);

            return affectRows == 1;
        }


        // ********************************************************************************
        // Implementation of deleteAll/deteleByForeignKeys/deleteByPrimaryKeys function		
        // ********************************************************************************

        // return number of deleted rows		
        public int deleteAll()
        {
            return _dbTool.ExecuteNoneQuery("SP_DEL_PAYMENTS_deleteAll");
        }

        // return number of deleted rows
        public int deleteByPrimaryKeys(System.Int32 PAY_ID)
        {
            SqlParameter[] parm = { new SqlParameter(PAYMENTSDTO._PAY_ID, PAY_ID) };
            return _dbTool.ExecuteNoneQuery("SP_DEL_PAYMENTS_deleteByPrimaryKeys", parm);
        }


    }
}